<?php
class Item{
	private $id;				//item id number
	private $category_id;	//parent category id number
	private $name;			//name of item
	private $description;	//description of item
	private $price;			//price of item
	private $image_id;		//id of image in image table
	
	function __construct($id = '0', $category_id = '0', $name = 'placeholder item', $description = '', $price = '999.99', $image_id = '')
	{
		$this->id = $id;
		$this->category_id = $category_id;
		$this->name = $name;
		$this->description = $description;
		$this->price = $price;
		$this->image_id = $image_id;
	}
	
	/**
	* Retrieves information of item with number that is passed in.
	*/
	function retrieveInfo($item_id)
	{
		$con = mysqli_connect('localhost','mrc02_search','searchtest','mrc0260_sportinggoodscompany') or die(mysqli_error($con));
		$query = "SELECT * FROM items WHERE id = '$item_id'";
		$result = mysqli_query($con, $query) or die(mysqli_error($con));
		mysqli_close($con);
		$row = mysqli_fetch_array($result);
		
		$this->id = $row['id'];
		$this->category_id = $row['category_id'];
		$this->name = $row['name'];
		$this->description = $row['description'];
		$this->price = $row['price'];
		$this->image_id = $row['image_id'];
	}
	
	function displayItem()
	{
		echo '<div id="item"><H3>'.
				$this->name.'</H3><br>
				<img src="/'.$this->image_id.'" height="150" width="150">
				Description: '.$this->description.'<br>
				Price: '.$this->price.'<br><br>'.
				'</div>';
	}
}